package com.ruoyi.resume.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.resume.domain.model.ResumeAnalysis;
import com.ruoyi.resume.domain.model.SplitResumeResult;
import com.ruoyi.resume.mapper.ResumeAnalysisMapper;
import com.ruoyi.resume.service.ResumeAnalysisService;
import com.ruoyi.resume.service.resumeComparisonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "简历智能分析")
@RestController
@RequestMapping("/analysis")
public class AnalysisController {
    @Autowired
    private resumeComparisonService resumeComparisonService;

    @Autowired
    private ResumeAnalysisService resumeAnalysisService;
    /**
     * 根据简历 ID 查询候选人的 AI 分析结果
     *
     * @param resumeId 简历 ID
     * @return 候选人的 AI 分析结果
     */
    @ApiOperation("根据简历 ID 查询候选人的 AI 分析结果")
    @ApiImplicitParam(name = "resumeId", value = "简历 ID", dataType = "Integer", paramType = "path", required = true)
    @GetMapping("/ai-evaluation/{resumeId}")
    @Anonymous
    public ResponseEntity<ResumeAnalysis> getAiEvaluationByResumeId(@PathVariable Integer resumeId) {
        // 调用服务获取 AI 分析结果
        ResumeAnalysis analysis = resumeAnalysisService.getAnalysisByResumeId(resumeId);

        if (analysis != null) {
            return ResponseEntity.ok(analysis);
        } else {
            return ResponseEntity.notFound().build();
        }
    }

    /**
     * 简历对比
     *
     * @author 张涵姣
     */

    // 上传两个简历的 ID 和可选的 prompt 语句进行对比
    @ApiOperation("上传两个简历 ID 和可选的 prompt 语句进行对比")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resumeId1", value = "简历 ID 1", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "resumeId2", value = "简历 ID 2", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "requirements", value = "可选的 prompt 语句", dataType = "String", paramType = "query")
    })
    @GetMapping("/compare-resumes")
    @Anonymous
    public ResponseEntity<String> compareResumes(
            @RequestParam("resumeId1") Integer resumeId1,
            @RequestParam("resumeId2") Integer resumeId2,
            @RequestParam(value = "requirements", required = false) String requirements) {

        // 调用简历对比服务，传入两个简历的 ID 和可选的 prompt
        String comparisonResult = resumeComparisonService.compare(resumeId1, resumeId2, requirements);

        return ResponseEntity.ok(comparisonResult);
    }
}
